<?php

class Model_DbTable_Apos_Productdesall extends Zend_Db_Table_Abstract {
	

	public function getAposDes($sCode){
		
		$whereStr = "SCODE LIKE '".$sCode."'";
		$row = $this->fetchRow($whereStr);
		if(!$row) return false;
		return $row->toArray();
	}
	
	public function getScodeList($shortCode){
		$whereStr = "SCODE LIKE '".$shortCode."%'";
		$rows = $this->fetchAll($whereStr,'SCODE ASC')->toArray();
		if(empty($rows)) return false;
		return $rows;		 
	}
	
	public function getAll(){
		
		$rows = $this->fetchAll("SCODE IS NOT NULL AND STOPSALES = 0");
		if(!$rows) return false;
		return $rows->toArray();
			
	}
	
	public function listAllByDes($des){
		$rows = $this->fetchAll("DESCRIPT like '%{$des}%'");
		if(!$rows) return false;
		return $rows->toArray();
	}
	
	public function listNewProducts(){
		
		$whereStr = "DESCRIPT LIKE '**%'";
		$rows = $this->fetchAll($whereStr,"SCODE ASC");
		if(!$rows) return false;
		return $rows->toArray();		
	
	}
	public function removeStar($sCode){

		$row = self::getAposDes($sCode);
		$des = $row["DESCRIPT"];
		$des = str_replace("**","", $des);
		$des = $des."  ";
		
		$data = array(
			"DESCRIPT" => $des 	
				);
		$this->update($data,"SCODE LIKE '".$sCode."'");
		
	}
	
	public function updateDes($sCode,$des){
		$len = strlen($des);
		if($len >60){
			
			$des = substr($des,0,60);
		}
		if($len < 60){
			
			$des = str_pad($des,60-$len);
		}
		
		$data = array(
				"DESCRIPT" => $des
		);
		$this->update($data,"SCODE LIKE '".$sCode."'");		
		
		
	}
	public function isBranded($sCode){
		$row = self::getAposDes($sCode);
		if(!$row) return false;
		
		if(strpos($row["DESCRIPT"],"#B")!==false) return "yes";
		
		return "no";
		
		
	}
	
	public function matchBcode($bCode){
		
		$whereStr = "SCODE LIKE '".$bCode."' OR BCODE LIKE '".$bCode."' OR BCODE2 LIKE '".$bCode."' ";
		$row = $this->fetchRow($whereStr);
		if(!$row) return false;
		return $row->toArray();
	}
	
	public function barcodeWithoutPrice(){
		
		$whereStr = " ( APRICE = 0 OR BPRICE = 0)  AND CAT NOT LIKE 'SERV' AND CAT NOT LIKE 'SERVI' AND  CAT NOT LIKE 'STATI' AND STOPSALES = 0";
		$rows = $this->fetchAll($whereStr);
		
		if(!(boolean)$rows) return false;
		return $rows->toArray();

	}
	
	
}

?>